package h0811;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author 不知名帅哥
 * @version 1.0
 * @description 符号运算
 * @date 2024/8/11 15:12
 */
public class CalculateOperator {
    static class Fractions {
        int fa;//分母
        int ch; //分子

        public Fractions() {
        }

        public Fractions(int fa, int ch) {
            this.fa = fa;
            this.ch = ch;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(getResult(s));
    }

    //操作数栈
    static LinkedList<Fractions> oper_num = new LinkedList<>();
    //操作符栈
    static LinkedList<Character> oper_sign = new LinkedList<>();

    private static String getResult(String s) {
        //运算符优先级 + - * /
        HashMap<Character, Integer> priority = new HashMap<>();
        priority.put('+', 1);
        priority.put('-', 1);
        priority.put('*', 2);
        priority.put('/', 2);

        //操作符的字符缓冲容器
        StringBuilder numStr = new StringBuilder();

        int i = 0;
        while (i < s.length()) {
            char c = s.charAt(i);

            //遇到数字字符
            if (c >= '0' && c <= '9') {
                //则将该数字所在操作数的剩余数字字符一次性探索完
                while (c >= '0' && c <= '9') {
                    numStr.append(c);
                    if (i + 1 >= s.length()) break;
                    i++;
                    c = s.charAt(i);
                }

                //探索玩后将数字变成分数压入操作数栈
                oper_num.addLast(new Fractions(1, Integer.parseInt(numStr.toString())));

                //注意清空操作数缓存容器
                numStr = new StringBuilder();
            }

            //遇到运算符
            if (c == '+' || c == '-' || c == '*' || c == '/') {
                //TODO 如果当前运算符小于栈顶操作符优先级，就要一直出栈。
                while (oper_sign.size() > 0 && oper_sign.getLast() != '(' && priority.get(c) <= priority.get(oper_sign.getLast())) {
                    //计算
                    calc();
                }
                oper_sign.addLast(c);
            } else if (c == ')') {
                while (oper_sign.getLast() != '(') {
                    //计算
                    calc();
                }
                //最后将 ( 出栈
                oper_sign.removeLast();
            } else if (c == '(') {
                //左括号直接压栈
                oper_sign.addLast(c);
            }

            i++;
        }

        while (oper_num.size() > 1) {
            //剩余的操作数大于1
            //计算
            calc();
        }
        Fractions res = oper_num.removeLast();
        //分母不能为0
        if (res.fa == 0) return "ERROR";  //

        //分子
        int res_ch = res.ch;
        //分母
        int res_fa = res.fa;
        //求出两个的最大公因数
        int factor = gcd(res_ch, res_fa);

        int a = res_ch / factor;
        int b = res_fa / factor;
        //计算符号，这里用乘法的原因是避免分子小分母大，结果为0.
        String sign = a * b < 0 ? "-" : "";
        if (b == 1) {
            return sign + a;
        } else {
            return sign + a + "/" + b;
        }
    }

    private static void calc() {
        //操作数顺序会对结果产生影响
        Fractions b = oper_num.removeLast(); //栈顶元素是运算符右边的操作数
        Fractions a = oper_num.removeLast(); //栈顶倒数第二个元素是运算符左边的操作数

        //运算符
        char op=oper_sign.removeLast();

        //记录运算结果
        Fractions result = new Fractions();

        switch (op){
            case '+':
                result.fa=a.fa*b.fa;
                result.ch=a.ch*b.fa+b.ch*a.fa;
                break;
            case '-':
                result.fa=a.fa*b.fa;
                result.ch=a.ch*b.fa-b.ch*a.fa;
                break;
            case '*':
                result.fa=a.fa*b.fa;
                result.ch=a.ch*b.ch;
                break;
            case '/':
                result.fa=a.fa*b.ch;
                result.ch=a.ch*b.fa;
                break;
        }
        //将结果添加到操作数栈
        oper_num.add(result);
    }

    //求最大公因数
    private static int gcd(int a, int b) {

        while (b != 0) {
            int temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }


}
